package a_java_48_day.day5;
/**
 * 连续最大和
 */

import java.util.*;
import java.lang.*;
public class Main2 {
    public static void main(String[] args) {
        List<Character>list = new ArrayList<>();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int sum=0;
        int ans=Integer.MIN_VALUE;;
        for(int i=0;i<n;i++){
            int num=in.nextInt();
            sum+=num;
            ans=Math.max(sum,ans);
            sum=sum<0?0:sum;
        }
        System.out.println(ans);
    }
}